package cn.ekgc.shopping

import org.apache.spark.sql.SparkSession

object FenXi {

  def saveToMysql(spark:SparkSession,sql:String,tableName:String  ) ={
    val df = spark.sql(sql)
    val props = new java.util.Properties()
    props.put("user","root")
    props.put("password","password")
    props.put("driver","com.mysql.cj.jdbc.Driver")
    df.write.jdbc("jdbc:mysql://beimei6-mysql:3306/shopping",tableName,props)
  }

  def preStatePeopleCount(spark:SparkSession) ={
    val sql =
      """
        |select state,count(1) as people_count from shopping.customers group by state
        |""".stripMargin
    saveToMysql(spark,sql,"state_people_count")
  }


}
